/*
 * @Author: szx
 * @Date: 2022-03-18 14:38:55
 * @LastEditTime: 2022-03-18 14:46:18
 * @Description:
 * @FilePath: \leetcode\400-499\406\406_2.js
 */
/**
 * @param {number[][]} people
 * @return {number[][]}
 */
var reconstructQueue = function (people) {
    people.sort((a, b) => {
        if (a[0] != b[0]) {
            return b[0] - a[0];
        } else {
            return a[1] - b[1];
        }
    });
    const queue = [];
    for (let i = 0; i < people.length; i++) {
        queue.splice(people[i][1], 0, people[i]);
    }
    return queue;
};
console.log(
    reconstructQueue([
        [7, 0],
        [4, 4],
        [7, 1],
        [5, 0],
        [6, 1],
        [5, 2]
    ])
);
